#include <motor.h>
#include <key.h>

static int motro_statu = 0;//正传1 反转0

void motor_init(void)
{
	//输入
    rt_pin_mode(PIN_MOTOR_A, PIN_MODE_OUTPUT);
    rt_pin_mode(PIN_MOTOR_B, PIN_MODE_OUTPUT);

    rt_pin_write(PIN_MOTOR_A, 0);
    rt_pin_write(PIN_MOTOR_B, 0);

}

static void motor_for(void)
{
    if(motro_statu == 1)
    {
        motor_stop();
        rt_thread_mdelay(500);
    }

    MOTOR_A(0);
    MOTOR_B(1);
    motro_statu = 0;
}

static void motor_bak(void)
{
    if(motro_statu == 0)
    {
        motor_stop();
        rt_thread_mdelay(500);
    }

    MOTOR_A(1);
    MOTOR_B(0);
    motro_statu = 1;
}

void motor_stop(void)
{
    MOTOR_A(0);
    MOTOR_B(0);
}


//-------------------------------------------------------------------
//
//-------------------------------------------------------------------

void motor_open(void)
{
    if(LIMIT_DOWN) return;

    motor_for();
}

void motor_close(void)
{
    if(LIMIT_UP) return;

    motor_bak();
}
